import {Component, ElementRef, Renderer2} from '@angular/core';
import {ApesField} from './apes-field';
import {ApiService} from '@core/services/http/api.service';
import {Events} from '@core/services/events/Events';
import {ExpressionService} from '@core/services/expression/ExpressionService';
import {SubjectService} from "@core/services/events/subject.service";

@Component({
  selector: 'formly-field-city-picker',
  template: `
    <apes-city-picker [formControl]="formControl"
                      [formlyAttributes]="field"
                      [apesPlaceHolder]="to.placeholder"
                      [apesReadonly]="to.readonly"
                      [apesDisabled]="to.disabled"
                      [level]="level"></apes-city-picker>
  `
})
export class FormlyFieldCityPicker extends ApesField {


  constructor(protected apiService: ApiService, protected events: Events, protected expressionService: ExpressionService, protected subject: SubjectService,
              protected elementRef: ElementRef, protected renderer: Renderer2) {
    super(apiService, events, expressionService, subject);
  }

  ngOnInit(): void {
    this.addDefalutPlaceholder('请选择');
    this.addEventListener(this.elementRef, this.renderer);
  }

  get type() {
    return this.to.type || 'text';
  }

  get level() {
    return this.to.level || 'district';
  }

}
